package com.start.security.providers;

import com.start.common.constant.StartConstant;
import com.start.security.authentication.UserAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;


@Component
public class UserAuthenticationProvider extends DaoAuthenticationProvider {

    /**
     * 初始化 将使用User专用的userDetailsService
     *
     * @param
     */
    public UserAuthenticationProvider(UserDetailsService userDetailsService) {
        setPasswordEncoder(StartConstant.passwordEncoder);
        setUserDetailsService(userDetailsService);
    }


    /**
     * 判断只有传入UserAuthenticationToken的时候才使用这个Provider
     * supports会在AuthenticationManager层被调用
     *
     * @param authentication
     * @return
     */
    public boolean supports(Class<?> authentication) {
        return UserAuthenticationToken.class.isAssignableFrom(authentication);
    }
}
